<?php

namespace App\Models\service;

use App\Models\AdminModel;
use App\Models\CustomerModel;
use App\Models\OrderModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProblemModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_service_problem';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    const PROGRAMME = [1 => '退回', 2 => '寄出', 3 => '销毁'];

    const STATUS = [1 => '待回复', 2 => '已回复', 3 => '已结案'];

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];


    //订单
    public function order(): BelongsTo {
        return $this->belongsTo(OrderModel::class, 'order_id');
    }

    //客户
    public function customer(): BelongsTo {
        return $this->belongsTo(CustomerModel::class, 'customer_id');
    }

    //类型
    public function type(): BelongsTo {
        return $this->belongsTo(ProblemTypeModel::class, 'type_id');
    }

    //提案人
    public function pro_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'pro_admin_id');
    }

    //结案人
    public function end_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'end_admin_id');
    }

    //赔偿
    public function compensate(): BelongsTo {
        return $this->belongsTo(CompensateModel::class, 'compensate_id');
    }

}
